-module (hello_server).
-export ([start_hello_server/0]).

start_hello_server() ->
    io:format("~p~n",[self()]),
    {ok,Listen}=gen_tcp:listen(5555,[binary]),
    {ok,Socket}=gen_tcp:accept(Listen),
    loop(Socket).

loop(Socket) ->
    receive
        {tcp,Socket,<<"quit\r\n">>} ->
            io:format("client quit~n"),
            gen_tcp:close(Socket);
        {tcp,Socket,Data} ->
            gen_tcp:send(Socket,"Hello:"),
            gen_tcp:send(Socket,Data),
            loop(Socket);
        {tcp_closed,Socket} ->
            io:format("client is lost~n")
    end.